home *** CD-ROM | disk | FTP | other *** search
Text File | 1992-04-20 | 5.5 KB | 268 lines | [TEXT/PJMM] |
- unit MyFMenus;
-
- { This program was written by Peter N Lewis, Mar 1992 in THINK Pascal 4.0.1 }
-
- interface
-
- procedure InitFMenus (default: procptr);
- { procedure default(themenu,theitem:integer) }
- procedure FinishFMenus;
- function GetFMenu (id: integer): MenuHandle;
- procedure AddFCommand (themenu, theitem: integer; command: OSType);
- procedure SetFCommand (command: OSType; cmdproc: procptr);
- { procedure cmdproc }
- procedure SetFSetMenu (command: OSType; smproc: procptr);
- { procedure smproc(themenu,theitem:integer) }
- procedure SetFBoth (command: OSType; cmdproc, smproc: procptr);
- procedure GetCommand (themenu, theitem: integer; var command: OSType);
- procedure DoCommand (themenu, theitem: integer; command: OSType);
- procedure DoFMenu (themenu, theitem: integer);
- procedure SetFMenus;
-
- implementation
-
- uses
- BaseGlobals;
-
- procedure DoSMP (themenu, theitem: integer; smp: procptr);
- inline
- $205F, $4E90;
-
- procedure DoDefCMDP (themenu, theitem: integer; cmdp: procptr);
- inline
- $205F, $4E90;
-
- procedure DoCMDP (cmdp: procptr);
- inline
- $205F, $4E90;
-
- type
- fmenuHeader = record
- visible: integer;
- count: integer;
- unknown1: integer;
- menuID: integer;
- unknown2: integer;
- unknown3: integer;
- name: str63;
- end;
- fmenuHeaderPtr = ^fmenuHeader;
- fmenuItem = packed record
- command: OSType;
- mark: char;
- unknown2: byte;
- cmdKey: char;
- disabled: byte;
- name: str63;
- end;
- fmenuItemPtr = ^fmenuItem;
- convertRecord = record
- menu, item: integer;
- cmd: OSType;
- cmdp, smp: procptr;
- end;
- convertArray = array[1..1000] of convertRecord;
- convertPtr = ^convertArray;
- convertHandle = ^convertPtr;
-
- var
- defaultproc: procptr;
- convert_count: integer;
- converts: convertHandle;
-
- {$S Init}
- procedure InitFMenus (default: procptr);
- { procedure default(themenu,theitem:integer) }
- begin
- defaultproc := default;
- convert_count := 0;
- converts := convertHandle(NewHandle(0));
- end;
-
- {$S Term}
- procedure FinishFMenus;
- begin
- DisposHandle(handle(converts));
- end;
-
- {$S Init}
- procedure AddFCommand (themenu, theitem: integer; command: OSType);
- begin
- if BAND(convert_count, 7) = 0 then
- SetHandleSize(handle(converts), (convert_count + 8) * SizeOf(convertRecord));
- convert_count := convert_count + 1;
- with converts^^[convert_count] do begin
- menu := themenu;
- item := theitem;
- cmd := command;
- cmdp := defaultproc;
- smp := nil;
- end;
- end;
-
- {$S Init}
- procedure NextPtr (var p: univ ptr; sp: univ ptr);
- begin
- p := ptr(longInt(sp) + sp^ + 2 - ord(odd(sp^)));
- end;
-
- {$S Init}
- function GetFMenu (id: integer): MenuHandle;
- var
- h: handle;
- mh: menuHandle;
- ph: fmenuHeaderPtr;
- p: fmenuItemPtr;
- s: string[70];
- i: integer;
- begin
- h := GetResource('fmnu', id);
- HLock(h);
- ph := fmenuHeaderPtr(h^);
- mh := NewMenu(ph^.menuID, ph^.name);
- NextPtr(p, @ph^.name);
- for i := 1 to ph^.count do begin
- if p^.name = '-' then
- AppendMenu(mh, '(-')
- else begin
- AddFCommand(ph^.menuID, i, p^.command);
- s := p^.name;
- if p^.mark <> chr(0) then
- s := concat(s, '!', p^.mark);
- if p^.cmdKey <> chr(0) then
- s := concat(s, '/', p^.cmdKey);
- if p^.disabled = 1 then
- s := concat('(', s);
- AppendMenu(mh, s);
- end;
- NextPtr(p, @p^.name);
- end;
- DisposHandle(h);
- GetFMenu := mh;
- end;
-
- {$S}
- procedure FindCommand (command: OSType; var cmdproc: procptr);
- var
- i: integer;
- begin
- i := 1;
- while i <= convert_count do begin
- with converts^^[i] do
- if cmd = command then begin
- cmdproc := cmdp;
- Exit(FindCommand);
- end;
- i := i + 1;
- end;
- cmdproc := defaultproc;
- end;
-
- {$S}
- procedure FindMenu (themenu, theitem: integer; var i: integer);
- begin
- i := 1;
- while i <= convert_count do begin
- with converts^^[i] do
- if (menu = themenu) and (item = theitem) then
- Exit(FindMenu);
- i := i + 1;
- end;
- i := -1;
- end;
-
- {$S Init}
- procedure SetFCommand (command: OSType; cmdproc: procptr);
- { procedure cmdproc }
- var
- i: integer;
- begin
- for i := 1 to convert_count do
- with converts^^[i] do
- if cmd = command then
- cmdp := cmdproc;
- end;
-
- {$S Init}
- procedure SetFSetMenu (command: OSType; smproc: procptr);
- { procedure smproc }
- var
- i: integer;
- begin
- for i := 1 to convert_count do
- with converts^^[i] do
- if cmd = command then
- smp := smproc;
- end;
-
- {$S Init}
- procedure SetFBoth (command: OSType; cmdproc, smproc: procptr);
- { procedure smproc }
- var
- i: integer;
- begin
- for i := 1 to convert_count do
- with converts^^[i] do
- if cmd = command then begin
- cmdp := cmdproc;
- smp := smproc;
- end;
- end;
-
- {$S}
- procedure GetCommand (themenu, theitem: integer; var command: OSType);
- var
- i: integer;
- begin
- FindMenu(themenu, theitem, i);
- if i = -1 then
- command := 'xxx0'
- else
- command := converts^^[i].cmd;
- end;
-
- {$S}
- procedure DoCmd (themenu, theitem: integer; cmdp: procptr);
- begin
- if cmdp = defaultproc then
- DoDefCMDP(themenu, theitem, cmdp)
- else
- DoCMDP(cmdp);
- end;
-
- {$S}
- procedure DoCommand (themenu, theitem: integer; command: OSType);
- var
- cmdproc: procptr;
- begin
- FindCommand(command, cmdproc);
- DoCmd(themenu, theitem, cmdproc);
- end;
-
- {$S}
- procedure DoFMenu (themenu, theitem: integer);
- var
- i: integer;
- begin
- FindMenu(themenu, theitem, i);
- if i = -1 then
- DoCmd(themenu, theitem, defaultproc)
- else
- with converts^^[i] do
- DoCmd(themenu, theitem, cmdp);
- if not quitNow then
- HiliteMenu(0);
- end;
-
- {$S}
- procedure SetFMenus;
- var
- i: integer;
- begin
- for i := 1 to convert_count do
- with converts^^[i] do
- if smp <> nil then
- DoSMP(menu, item, smp);
- end;
-
- end.